<template>
  <div class="collect-page">
    <van-nav-bar fixed title="我的收藏" />
    <van-list
    v-model="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onload">
    <article-item :atc="item" v-for="item in rows" :key="item.id" />
    </van-list>
  </div>
</template>

<script>
import { getArticlesCollect } from '@/api/article'
export default {
  name: 'collect-page',
  data () {
    return {
      rows: [],
      loading: false,
      // 是否全部加载完毕
      finished: false,
      current: 1,
      sorter: 'weight_desc'
    }
  },
  methods: {
    async onload () {
      const res = await getArticlesCollect({
        optType: 2,
        page: this.current,
        pageSize: 10
      })

      this.rows.push(...res.data.data.rows)

      // 将 loading 设置为 false
      this.loading = false

      // 防止过度操作导致的其他 Bug
      // 写代码时要考虑到代码的健壮性

      if (this.current >= res.data.data.pageTotal) {
        // 加载完毕了
        this.finished = true
      }

      // 加载完毕后让 current 自增
      this.current++
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
